﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Assets.Script.Config;
using LuaInterface;


public class SlgMainEnter : MonoBehaviour {
    private LuaState _luaState = null;
    
    private void LoadLuaConfig()
    {
        _luaState = new LuaState();
        _luaState.AddSearchPath(BonConst.FrameworkRoot + "/Lua");
        _luaState.Start();
        _luaState.DoFile("Config/ConfigManager");
        _luaState.DoFile("Logic/CsharpLuaInterface");
        //
    }

    //public object[] CallFunction(string funcName, params object[] args)
    //{
    //    try
    //    {
    //        LuaFunction func = _luaState.GetFunction(funcName);
    //        if (func != null)
    //        {
    //            return func.Call(args);
    //        }
    //    }
    //    catch (System.Exception ex)
    //    {
    //        Debug.LogErrorFormat("call lua func error:{0},err:{1}", funcName, ex.ToString());
    //    }


    //    return null;
    //}


    private void Start()
    {
        StartGame();
    }
    private void Update()
    {
        QueueLoadMgr.Instance.Update();
    }

    private void StartGame()
    {
        QueueLoadMgr.Instance.Init();
        QueueLoadMgr.Instance.AddLoadTask(ConfigManager.Instance.unitBaseLoader);
        QueueLoadMgr.Instance.AddLoadTask(ConfigManager.Instance.skillActionLoader);
        QueueLoadMgr.Instance.AddLoadTask(ConfigManager.Instance.heroEffLoader);
        QueueLoadMgr.Instance.AddLoadTask(ConfigManager.Instance.SkillLoader);
        QueueLoadMgr.Instance.AddLoadTask(ConfigManager.Instance.SkillEffectLoader);
        QueueLoadMgr.Instance.AddLoadTask(ConfigManager.Instance.LanSetting);
        QueueLoadMgr.Instance.AddLoadTask(ConfigManager.Instance.LangLoader);
        QueueLoadMgr.Instance.onLoadConfigDoneComplete += ConfigDone;
        QueueLoadMgr.Instance.StartLoad();
    }

    private void ConfigDone()
    {
        string json = Resources.Load("HeroFight/HeroBattleJson_5").ToString();
        ReportDetail m_pReport = ConfigManager.ConvertReportDetail(json);
        SlgBattleMgr.CreateInstance(true);
        List<HeroVo> heros = new List<HeroVo>();
        List<SoldierVo> soldiers = new List<SoldierVo>();
        List<ActionNode> actions = new List<ActionNode>();
        //HBDataCenter.Instance.Report2Slg_Heros(heros, m_pReport);
        //HBDataCenter.Instance.ConvertActionNode(actions, HBDataCenter.Instance.GetFirst(m_pReport));
        //soldiers = new List<SoldierVo>()
        //{
        //    new SoldierVo() {hp = 100,pId = 101, pos = 1,m_bleft = true,beforeHp = 100,afterHp = 50,
        //        config = new SoliderInfo() { pId = 101,step = 1,model = "Battle/Troop/batman/Prefab/batman",prefabName = "batman",attackRange = 0.7f,lookRange = 20} },

        //    new SoldierVo() {hp = 100,pId = 201, pos = 2,m_bleft = true,beforeHp = 100,afterHp = 50,
        //        config = new SoliderInfo() { pId = 201,step = 1,model = "Battle/Troop/shooter/Prefab/shooter",prefabName = "shooter",attackRange = 10,lookRange = 20} },

        //    new SoldierVo() {hp = 100,pId = 301, pos = 3,m_bleft = true,beforeHp = 100,afterHp = 50,
        //        config = new SoliderInfo() { pId = 301,step = 1,model = "Battle/Troop/knight/Prefab/knight",prefabName = "knight",attackRange = 0.7f,lookRange = 20} },

        //    new SoldierVo() {hp = 100,pId = 101, pos = 6,m_bleft = false,beforeHp = 100,afterHp = 50,
        //        config = new SoliderInfo() { pId = 101,step = 1,model = "Battle/Troop/batman/Prefab/batman",prefabName = "batman",attackRange = 0.7f,lookRange = 20} },

        //    //new SoldierVo() {hp = 100,pId = 101, pos = 5,m_bleft = false,beforeHp = 100,afterHp = 50,
        //    //    config = new SoliderInfo() { pId = 101,step = 1,model = "Battle/Troop/batman/Prefab/batman",prefabName = "batman",attackRange = 0.7f,lookRange = 20} }
        //};

        HBDataCenter.Instance.Report2SLG(soldiers, heros, actions, m_pReport);

        SlgBattleMgr.Instance.Init(soldiers, heros, null);
    }
}
